package com.ecmcloud.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ecmcloud.common.dto.Result;
import com.ecmcloud.common.utils.JsonMapperUtils;
import com.ecmcloud.service.IFormService;
import com.ecmcloud.vo.FormRemoteSelectOptionParamVo;
import com.fasterxml.jackson.core.type.TypeReference;

import cn.hutool.core.map.MapUtil;
import cn.hutool.http.HttpUtil;

@Service
public class FormServiceImpl implements IFormService {
	
    /**
     * 远程请求下拉选项
     *
     * @param formRemoteSelectOptionParamVo
     * @return
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
    public Object selectOptions(FormRemoteSelectOptionParamVo formRemoteSelectOptionParamVo) {
        String remoteUrl = formRemoteSelectOptionParamVo.getRemoteUrl();
        String s = HttpUtil.post(remoteUrl,"");
        List<Map> mapList = JsonMapperUtils.getInstance().parseObject(s, new TypeReference<List<Map>>() {});
        for (Map map : mapList) {
            String str = MapUtil.getStr(map, "key");
            map.put("key",str);
        }
        return Result.success(mapList);
    }
}
